﻿<view:DialogViewBase x:Class="SqlExport.View.OptionsWindow"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                     xmlns:viewModel="clr-namespace:SqlExport.ViewModel"
                     xmlns:options="clr-namespace:SqlExport.Views.Options"
                     xmlns:converters="clr-namespace:SqlExport.View.Converters" 
                     xmlns:view="clr-namespace:SqlExport.View"
                     Icon="/SQLExport;component/SqlExport.ico"
                     Title="Options" Height="342" Width="773">
    <Window.DataContext>
        <viewModel:OptionsViewModel/>
    </Window.DataContext>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <TabControl Margin="3,3,3,0">
            <TabItem Header="Database">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <DataGrid ItemsSource="{Binding Databases}" SelectedItem="{Binding SelectedDatabase}" AutoGenerateColumns="False" IsReadOnly="True">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
                            <DataGridTextColumn Header="Connection String" Binding="{Binding ConnectionString}" Width="*"/>
                            <DataGridTextColumn Header="Type" Binding="{Binding Type}"/>
                        </DataGrid.Columns>
                    </DataGrid>
                    <StackPanel Grid.Column="1" Margin="3,0,0,0">
                        <Button Content="{StaticResource ArrowUpIcon}" Command="{Binding MoveUpCommand}" />
                        <Button Content="{StaticResource ArrowDownIcon}" Margin="0,3,0,0" Command="{Binding MoveDownCommand}" />
                        <Button Content="{StaticResource AddIcon}" Margin="0,3,0,0" Command="{Binding AddDatabaseCommand}" />
                        <Button Content="{StaticResource DeleteIcon}" Margin="0,3,0,0" Command="{Binding DeleteDatabaseCommand}" />
                    </StackPanel>
                    <GroupBox Grid.Row="1" Header="Connection Details" IsEnabled="{Binding SelectedDatabase, Converter={StaticResource NullToBooleanConverter}}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <TextBlock Text="Name" VerticalAlignment="Center"/>
                            <TextBox Grid.Column="1" Margin="3,3,0,0" Text="{Binding SelectedDatabase.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                            <TextBlock Grid.Row="1" Text="Connection String" VerticalAlignment="Center"/>
                            <TextBox Grid.Column="1" Grid.Row="1" Margin="3,3,0,0" Text="{Binding SelectedDatabase.ConnectionString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                            <TextBlock Grid.Row="2" Text="Type" VerticalAlignment="Center"/>
                            <ComboBox Grid.Column="1" Grid.Row="2" Margin="3,3,0,0" ItemsSource="{Binding DatabaseTypes}" SelectedItem="{Binding SelectedDatabase.Type, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        </Grid>
                    </GroupBox>
                </Grid>
            </TabItem>
        </TabControl>
        <Grid Grid.Row="1" Grid.ColumnSpan="2" Margin="3">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Button Style="{StaticResource DialogButtons}" Content="_View File" HorizontalAlignment="Left" Command="{Binding OpenFileCommand}"/>
            <Button Grid.Column="1" Style="{StaticResource DialogButtons}" Command="{Binding OkCommand}" Content="_Ok" IsDefault="True" Margin="0,0,3,0"/>
            <Button Grid.Column="2" Style="{StaticResource DialogButtons}" Content="_Cancel" IsCancel="True"/>
        </Grid>
    </Grid>
</view:DialogViewBase>